<include file="Public/header.html" />
<style>
.font_color{color: #ff5722;}
.xq_tc_d1{display: none;width: 100%;height: 100%;background: rgba(0,0,0,0.2);position: fixed;top: 0;left: 0;z-index: 10;}
.xq_tc_d2{width: 70%;height: 80%;position: fixed;top: 40%;left: 20%;margin-top: -310px;margin-left: -200px;background:#fff;border-radius: 4px; overflow-x: hidden;
    overflow-y: scroll;}
.xq_tc_d3{background-color:#00968817;height:35px;margin-bottom:25px;padding-top:15px;padding-left:10px;color:#795548;}
.xq_tc_s1{float:right;margin-right:10px;}
.uploadImg{width:150px;max-height:150px;min-height:150px;float:left;margin-right:15px;margin-top:15px;position:relative;display: flex;align-items: center;border:1px solid #ddd;}
.uploadImg img{width:100%;align-items: center}
.file_del{position:absolute;right:-12px;top:-12px;width:24px;height:24px;line-height:24px;border-radius:50%; text-align:center;background:red;color:#fff;z-index:5;}
.serve_div {width:220px;height:40px;float:left;margin-right:20px;}
.ser_add_div{width:286px;height:40px;float:left;margin-right:20px;margin-top:10px;}  
.font_color{color: #ff5722;} 
</style>
</head>
<body>
	<div class="x-body">
		<form class="layui-form">
			<div class="layui-form-item">
			    <label class="layui-form-label">项目名称</label>
			    <div class="layui-input-block">
			       	<input type="text" name="title" value="{$list['title']}"  autocomplete="off" class="layui-input" lay-verify="required">
			    </div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style='color:red'>*</span>项目佣金</label>
				<div class="layui-input-block">
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][0]}" class="layui-input" placeholder="T0佣金">
					</div>
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][1]}" class="layui-input" placeholder="T1佣金">
					</div>
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][2]}" class="layui-input" placeholder="T2佣金">
					</div>
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][3]}" class="layui-input" placeholder="T3佣金">
					</div>
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][4]}" class="layui-input" placeholder="T4佣金">
					</div>
					<div class="layui-input-inline">
						<input type="text" name="commission[]" value="{$list['commission'][5]}" class="layui-input" placeholder="T5佣金">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style='color:red'>*</span>结算周期</label>
				<div class="layui-input-block">
					<input type="text" name="cycle" lay-verify="required" placeholder="单位：天" class="layui-input" value="{$list['cycle']}">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style='color:red'>*</span>跳转链接</label>
				<div class="layui-input-block">
					<input type="text" name="url" lay-verify="required" placeholder="" class="layui-input" value="{$list['url']}">
				</div>
			</div>
			<div class="layui-form-item">
			   	<label class="layui-form-label" >列表图</label>
			    <button type="button" class="layui-btn" id="upload_kf">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
				<div class="layui-input-block">
					<input id="img_val" name="img" type="hidden" value="{$list['img']}" />
					<?php if(!empty($list['img'])){ ?>
					<img id="img" style="width: 150px;height: 150px;" src="{$list['img']}" />
					<?php }else{ ?>
					<img id="img" style="width: 150px;height: 150px;" src="__ROOT__/Public/images/z_add.png" />
					<?php } ?>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">详情轮播图</label>
				<div class="layui-input-block">
				    <button class="layui-btn " type ='button' onclick="$('#file').click();">图片上传</button>
				    <div class="font_color" style="float:none;">图片最佳尺寸为800px*480px，宽高比例为10:6 </div>
				    <input id="file" type="file" multiple="" style="display: none;" onchange="changepreview(this)" >
					<div id="demo" class="demo">
					  <div class="upload_box">
					    <div class="upload_main single_main">						      		
					      <div id="preview" class="upload_preview">
					      	<div class="showfiles">
					      		<if condition="$list['lists_img']">
					      			<for start="0" end="count($list['lists_img'])" >
					      				<div class="upload_append_list" >
											<input type="hidden" name="old_img[]" value="{$list['lists_img'][$i]}"  />
											<a href="javascript:;" class="imgBox">
												<div class="uploadImg">
													<span class="file_del" title="删除"><i class="layui-icon">&#x1006;</i></span>
													<img class="upload_image" src="{$path}{$list['lists_img'][$i]}" />                                                                 
												</div>
											</a>
										</div>
					      			</for>
					      		</if>
					      	</div>						      							        
					      </div>
					    </div>
					  </div>
					</div>   
				</div>			
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">套餐详情</label>
				<div class="layui-input-block">
					<input type="hidden" id="package_content" value="{$list['package']}" />
					<div lay-verify="package_content" id='package_content_edit' name="package_content" style="height: 220px;width: 100%;"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">任务详情</label>
				<div class="layui-input-block">
					<input type="hidden" id="task_content" value="{$list['content']}" />
					<div lay-verify="task_content" id='task_content_edit' name="task_content" style="height: 220px;width: 100%;"></div>
				</div>
			</div>
			<!--<div class="layui-form-item">
			    <label class="layui-form-label">参与时间</label>
			    <div class="layui-input-block">
			        <input type="text" name="datetime" id="datetime" class="layui-input" value="{$list['datetime']}" lay-verify="required">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">项目佣金</label>
			    <div class="layui-input-block">
			       	<input type="number" name="reprice" value="{$list['reprice']}"  autocomplete="off" class="layui-input" lay-verify="required">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">审核周期</label>
			    <div class="layui-input-block">
			       	<input type="number" name="cycle" value="{$list['cycle']}"  autocomplete="off" class="layui-input" lay-verify="required">
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">提交限制</label>
			    <div class="layui-input-block">
			    	<input type="radio" name="flag" value="1" title="单次" <?php if($list['flag']==1||empty($list['flag'])){echo 'checked';} ?>>
			    	<input type="radio" name="flag" value="2" title="多次" <?php if($list['flag']==2){echo 'checked';} ?>>
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">凭证验证</label>
			    <div class="layui-input-block">
			    	<input type="checkbox" name="is_img" title="图片" <?php if($list['is_img']==1){echo 'checked';} ?>>
			    	<input type="checkbox" name="is_txt" title="文字" <?php if($list['is_txt']==1){echo 'checked';} ?>>
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">图文详情</label>
			    <div class="layui-input-block">
			       	<input type="hidden" id="consult_content"  value="{$list['content']}" />
					<div lay-verify="jump_content" id='jump_content_edit' name="content" style="height: 220px;width: 100%;"></div>
			    </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">注意事项</label>
			    <div class="layui-input-block">
			       	<textarea class="layui-textarea" name="note">{$list.note}</textarea>
			    </div>
			</div>-->
			<input type="hidden" name="id" value="{$id}" />
			
			<div class="layui-form-item" style="display: none;">
                <label for="L_sign" class="layui-form-label"></label>
               <input type="button" class="layui-btn" id="submitBtn" key="set-mine" lay-filter="save" lay-submit />
           </div>
		</form>
	</div>
	
	<include file="Public/footer.html" />
	<script type="text/javascript" src="__ROOT__/Public/js/tools.js"></script> 
	<script type="text/javascript" src="__ROOT__/Public/js/jquery.min.js"></script> 
	<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/ueditor/ueditor.config.js?21"></script>
	<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/ueditor/ueditor.all.js?122"> </script>
	<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/ueditor/lang/zh-cn/zh-cn.js"></script>
	<script>
		$(function(){
    		var ue = UE.getEditor('jump_content_edit',{
				toolbars: [[
					'fullscreen', 'source', '|','cleardoc','simpleupload','insertframe',
					'preview','undo','bold','indent','italic',
					'underline','strikethrough','formatmatch','fontfamily',
				 	'fontsize','emotion','justifyleft','justifyright',
					'justifycenter','justifyjustify','forecolor'
				]]
			});
			var notice_content = $("#consult_content").val();
			ue.ready(function() {
	  			ue.setContent(notice_content);
			});
			
			var ue1 = UE.getEditor('package_content_edit',{
				toolbars: [[
					'fullscreen', 'source', '|','cleardoc','simpleupload','insertframe',
					'preview','undo','bold','indent','italic',
					'underline','strikethrough','formatmatch','fontfamily',
					'fontsize','emotion','justifyleft','justifyright',
					'justifycenter','justifyjustify','forecolor'
				]]
			});
			var package_content = $("#package_content").val();
			ue1.ready(function() {
				ue1.setContent(package_content);
			});
			
			var ue2 = UE.getEditor('task_content_edit',{
				toolbars: [[
					'fullscreen', 'source', '|','cleardoc','simpleupload','insertframe',
					'preview','undo','bold','indent','italic',
					'underline','strikethrough','formatmatch','fontfamily',
					'fontsize','emotion','justifyleft','justifyright',
					'justifycenter','justifyjustify','forecolor'
				]]
			});
			var task_content = $("#task_content").val();
			ue2.ready(function() {
				ue2.setContent(task_content);
			});
    	});
		layui.use(['form', 'layer','laydate','upload'], function() {
			$ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;
			var laydate = layui.laydate;
           	//日期时间范围
			laydate.render({
			    elem: '#datetime'
			    ,type: 'datetime'
			    ,range: true
			    ,trigger: 'click' 
			});
			var upload = layui.upload;
	    	//执行实例
			var uploadInst = upload.render({
			    elem: '#upload_kf' //绑定元素
			    ,url: "{:U('Home/Web/System/do_upload')}" //上传接口
			    ,done: function(res){
			    	//上传完毕回调
			    	console.log(res);
			    	$('#img').attr('src',res.path);
			    	$('#img_val').val(res.path);
			    }
			    ,error: function(){
			    	//请求异常回调
			    }
			});
			form.on('submit(save)', function(data){	
				var tjing = parent.layer.msg('提交中...', {icon: 16,shade: 0.3,time: 60*1000}); 
		        var form = document.forms[0];
	  		    var formData = new FormData(form);
				/*var cid = $('select[name="cid"]').val();
				if(!cid){
					parent.layer.msg('请先选择分类', {icon: 2,offset: '40%',time:2000,shade: 0.3});
					return false;
				}*/
				

				$("#preview").find(".upload_append_list_add").each(function(e){
					var fileval = $(this).find("input").val();
					var filename = $(this).find("input").attr("filename");
					formData.append('lists_img[]',convertBase64UrlToBlob(fileval));			
				})

					
				$.ajax({
			        url: "{:U('Home/Web/Project/do_project')}",
			        type : "POST",
			        data :formData,
			        dataType:"text",
			        processData : false,         
			        contentType : false,      
			        success:function(data){
			            parent.layer.close(tjing);
		               	if(data == '1'){
		                 	parent.layer.msg('提交成功', {icon: 1,offset: '40%',time:2000,shade: 0.3},function(){ 
					        	parent.location.reload();
						 	})
		               	}else if(data == '2'){
		              	 	parent.layer.msg('提交失败', {icon: 2,offset: '40%',time:2000,shade: 0.3});
		               	}else{
		               		parent.layer.msg(data, {icon: 2,offset: '40%',time:2000,shade: 0.3});
		               	}
			        }
			    });						
	           		
	            return false;
          	});
		});
	
		//多图图片上传
		function changepreview(files){
			var files = files.files; 
			var num = 1;
			$("#demo").find(".upload_append_list").each(function(){
				num++;
			})
			if(num>9){
				layer.msg("最多上传9张图片", {icon: 2,offset: '40%',time:2000,shade: 0.3});
				return false;
			}
			var t_num = files.length +num ;
			if(t_num>9){
				layer.msg("最多上传9张图片", {icon: 2,offset: '40%',time:2000,shade: 0.3});
				return false;
			}
			for (var i = 0;i < files.length; i++) {
				file = files[i];
				setup_reader(file);		
			}	
		}
		
		function setup_reader(file){
			if(!new RegExp("(jpg|jpeg|png)+","gi").test(file.type)){  
		        layer.msg("图片上传：文件类型必须是JPG、JPEG、PNG", {icon: 2,offset: '40%',time:2000,shade: 0.3});
		        return;  
		     }
			var reader = new FileReader();
			reader.onload = function(e) {
				var base64Img= e.target.result;
		        var _ir=ImageResizer({  
		        resizeMode:"auto"  
		        ,dataSource:base64Img  
		        ,dataSourceType:"base64"  
		        ,maxWidth:1200   
		        ,maxHeight:1200 
		        ,onTmpImgGenerate:function(img){ }   
		        ,success:function(resizeImgBase64,canvas){
                 preview(file,resizeImgBase64,resizeImgBase64.substr(22));
				
		        },debug:false});
				
			}	
			reader.readAsDataURL(file);	
		}
		
		function preview(file,srcval,fileval){
			var html = "";		
			// 图片上传的是图片还是其他类型文件
			if (file.type.indexOf("image") == 0) {
				html += '<div class="upload_append_list upload_append_list_add" size="'+file.size+'">';
				html += '	<input type="hidden" name="" value="'+fileval+'" filename="'+file.name+'" />';
				html += '	<a href="javascript:;" class="imgBox">';
				html += '		<div class="uploadImg">';
				html += '<span class="file_del" title="删除" ><i class="layui-icon">&#x1006;</i></span>';   // 删除按钮的html
				html += '			<img class="upload_image" src="' + srcval + '" />';                                                                 
				html += '		</div>';
				html += '	</a>';
				html += '</div>';   	
			}
		
			$("#preview").find(".showfiles").append(html);	
			$('img').zoomify();
		}
		
		$(document).on("click", ".file_del",function() {
			$(this).parents('.upload_append_list').remove();			
		});
		
		function convertBase64UrlToBlob(urlData){
		    var bytes=window.atob(urlData.split(',')[1]);    
		    var ab = new ArrayBuffer(bytes.length);
		    var ia = new Uint8Array(ab);
		    for (var i = 0; i < bytes.length; i++) {
		        ia[i] = bytes.charCodeAt(i);
		    }
		    return new Blob( [ab] , {type : 'image/jpg'});
	   	}
	</script>
</body>
</html>
